#ifndef QNode_h
#define QNode_h
#include <list>
#include<vector>
#include "GameObject.h"
#include "QRectangle.h"

using namespace std;//for using "list"

class QNode
{
public:
	QNode *_tl,*_tr, *_bl, *_br;
	QNode() { _tl=_tr=_bl=_br=NULL; }
	QNode(int id, QRectangle bound)
	{
		_bound=bound;
		_idNode=id;

		_tl = NULL;
		_tr = NULL;
		_bl = NULL;
		_br = NULL;
	}
	~QNode()
	{
		if(_tl!=NULL)
			delete _tl;
		if(_tr!=NULL)
			delete _tr;
		if(_bl!=NULL)
			delete _bl;
		if(_br!=NULL)
			delete _br;
		_tl = _tr = _bl = _br = NULL;
	}
	QNode *GetChildNode(int index)
	{
		switch (index)
		{
		default: return NULL;
		case 1: return _tl;
		case 2:return _tr;
		case 3: return _bl;
		case 4: return _br;
		}
	}

	vector<GameObject*> GetListGameObj()
	{
		return _vectorGameObjects;
	}

	int GetNodeID()
	{
		return _idNode;
	}
	int GetParentId()
	{
		return (int)(_idNode / 8);
	}
	void SetChild(int index, QNode *n)
	{
		switch (index)
		{
		default:break;
		case 1: _tl = n; break;
		case 2: _tr = n; break;
		case 3: _bl = n; break;
		case 4: _br = n; break;
		}
	}

	QRectangle GetBound()
	{
		return _bound;
	}
	void QNode::InsertObject(GameObject* gameObject)
	{
		_vectorGameObjects.push_back(gameObject);
	}

private:

	int _idNode;
	vector<GameObject*> _vectorGameObjects;

	// moving-bound
	QRectangle _bound;
};

#endif